/**
 * 本文件创建于 :2009-12-20<br>
 * @version 
 */
package com.monlyu.action;

import com.monlyu.util.ActionUtil;

/**
 * 分页标签
 * 
 * @author monlyu
 */
public class Page {
	/** 总条数 */
	private int total;
	/** 每页显示的行数 */
	private int size = ActionUtil.PAGE_SIZE;
	/** 当前页 */
	private int current;
	/** 总页数 */
	private int pageCount;
	/** 当前数据库中的起始位置 */
	private int start;

	public Page() {
	}

	public Page(int _total) {
		total = _total;
		pageCount = total / size;
		if (total % size > 0) {
			pageCount++;
		}
		current = 1;
		start = 0;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public int getCurrent() {
		return current;
	}

	public void setCurrent(int current) {
		this.current = current;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	/**
	 * 首页
	 */
	public void first() {
		current = 1;
		start = 0;
	}

	/**
	 * 上一页
	 */
	public void previous() {
		if (current == 1) {
			return;
		}
		current--;
		start = (current - 1) * size;
	}

	/**
	 * 下一页
	 */
	public void next() {
		if (current < pageCount) {
			current++;
		}
		start = (current - 1) * size;
	}

	/**
	 * 最后一页
	 */
	public void last() {
		current = pageCount;
		start = (current - 1) * size;
	}

	/**
	 * 刷新
	 * 
	 * @param _current
	 */
	public void refresh(int _current) {
		current = _current;
		if (current > pageCount) {
			last();
		}
	}
}
